#ifndef _MAP_H_
#define _MAP_H_

/*
*  Map.h
 *  Untitled
 *
 *  Created by Guo Wei Tan on 1/20/14.
 *  Copyright 2014 Catropico. All rights reserved.
 *
 */
#include "cocos2d.h"
#include "Supporting/Enums/EnumCharacterState.h"
#include "Supporting/Singleton.h"

class GameManager;
class Obstacle;

using namespace cocos2d;

class GameMap: public Singleton<GameMap>
{
private:
	const static int MAP_GRID_HEIGHT = 8; //number of lanes in map
	const static int UNSCALED_LANE_TOP_LIMIT = 120; // pixels from the top
	const static int UNSCALED_LANE_BOTTOM_LIMIT = 120; // pixels from the bottom

	const static int OBSTACLE_SPRITE_SHEET_HEIGHT = 3; //number of obstacles in the sprite sheet column
	const static int OBSTACLE_SPRITE_SHEET_WIDTH = 4; //number of obstcles in the sprite sheet row
	const static int OBSTACLE_SPRITE_WIDTH = 96;

	GameManager* _screenHolder;
	CCSize		_screenSize;
	float 		_scaleFactor;
	int			_bgEndPos, _pixelsPerGrid;
	int			_obstacleWidth, _bgWidth, _bgTopBound, _bgBottomBound;

	CCSprite*	_pBgSprite1;
	CCSprite*	_pBgSprite2;
	CCSprite** 	_obstacleSprites;
	CCArray*	_obstacles;
	
	void setupObstacleImage();
	void setupMapImage(CCString* imageDirectory);
	void updateMap(float xSpeed);
	void updateObstacle(float xSpeed);

public:

	//===== CONSTRUCTOR =====
	GameMap(); // do not use
	void init(CCString* pMapImageDirectory, GameManager* screenHolder);
	//===== DESTRUCTOR =====
	~GameMap();

	//===== FUNCTIONS =====
	void update(float xSpeed);
	bool checkCollisionWithObstacles(CCRect rect, CCPoint sourcePoint);
	bool isInSameLane(CCPoint point1, CCPoint point2);
	EnumCharacterState getNextGrid(float yCoord, bool isObstacle=false);
	
	//===== GETTERS =====
	float getScaleFactor(){return _scaleFactor;}
	int getPixelsPerGrid() {return _pixelsPerGrid; }
	int getScreenWidth() {return _screenSize.width;}
	int getScreenHeight() {return _screenSize.height;}
	int getScreenGridHeight() {return MAP_GRID_HEIGHT;}
	int getScreenTopBound() {return _bgTopBound;}
	int getScreenBottomBound() {return _bgBottomBound;}
	CCPoint getCharStartPoint();
	CCPoint getRandomCatStartPoint();
	CCPoint getCatStartPoint(int laneNumber);
};

#endif 
